package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CommissionPresetGroup;
import com.ruoyi.system.service.ICommissionPresetGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/hmk/commissionPresetGroup")
public class CommissionPresetGroupController extends BaseController {
    @Autowired
    private ICommissionPresetGroupService commissionPresetGroupService;

    /**
     * 查询分佣预设组列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommissionPresetGroup commissionPresetGroup) {
        startPage();
        List<CommissionPresetGroup> list = commissionPresetGroupService.selectCommissionPresetGroupList(commissionPresetGroup);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:export')")
    //@Log(title = "分佣预设组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommissionPresetGroup commissionPresetGroup) {
        List<CommissionPresetGroup> list = commissionPresetGroupService.selectCommissionPresetGroupList(commissionPresetGroup);
        ExcelUtil<CommissionPresetGroup> util = new ExcelUtil<CommissionPresetGroup>(CommissionPresetGroup.class);
        util.exportExcel(response, list, "分佣预设组数据");
    }


    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(commissionPresetGroupService.selectCommissionPresetGroupById(id));
    }

    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:query')")
    @GetMapping(value = "/selectAll")
    public AjaxResult selectAll() {
        return success(commissionPresetGroupService.selectAll());
    }


    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:add')")
    //@Log(title = "分佣预设组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommissionPresetGroup commissionPresetGroup) {
        return toAjax(commissionPresetGroupService.insertCommissionPresetGroup(commissionPresetGroup));
    }

    /**
     * 修改分佣预设组
     */
    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:edit')")
    //@Log(title = "分佣预设组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommissionPresetGroup commissionPresetGroup) {
        return toAjax(commissionPresetGroupService.updateCommissionPresetGroup(commissionPresetGroup));
    }

    /**
     * 删除分佣预设组
     */
    @PreAuthorize("@ss.hasPermi('hmk:commissionPresetGroup:remove')")
    //@Log(title = "分佣预设组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(commissionPresetGroupService.deleteCommissionPresetGroupByIds(ids));
    }
}
